<template>
  <div style="width:800px">
    <div class="xian"></div>
    <el-card class="box-card">
      <el-form ref="form" :model="form" label-width="100px" size="small">
        <el-form-item label="网站标题">
          <el-input v-model="form.title" maxlength="500" placeholder="请输入描述网站的标题"></el-input>
        </el-form-item>
        <el-form-item label="网站关键字">
          <el-input v-model="form.keywords" maxlength="500" placeholder="请输入描述网站的关键字"></el-input>
        </el-form-item>
        <el-form-item label="网站描述">
          <el-input v-model="form.description" maxlength="500" placeholder="请输入描述网站的详细信息"></el-input>
        </el-form-item>
        <el-form-item label="网站Logo">
          <el-row :gutter="1">
            <el-col :span="10">
              <el-input v-model="form.logoUrl" maxlength="500" placeholder="请上传网站Logo"></el-input>
            </el-col>
            <el-col :span="4">
              <el-upload action="/api/uploadImg" name="multipartFile" :show-file-list="false" accept="image/*" :on-success="logoSuccess" :on-error="uploadError">
                <el-button type="primary">上传
                  <i class="el-icon-upload el-icon--right"></i>
                </el-button>
              </el-upload>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="form.cellPhone" maxlength="500" placeholder="请输入联系电话"></el-input>
        </el-form-item>
         <el-form-item label="联系邮箱">
          <el-input v-model="form.email" maxlength="200" placeholder="请输入联系邮箱"></el-input>
        </el-form-item>
        <el-form-item label="微信二维码">
          <el-row :gutter="1">
            <el-col :span="10">
              <el-input v-model="form.wechat" maxlength="500" placeholder="请上传微信二维码"></el-input>
            </el-col>
            <el-col :span="4">
              <el-upload action="/api/uploadImg" name="multipartFile" :show-file-list="false" accept="image/*" :on-success="wechatSuccess" :on-error="uploadError">
                <el-button type="primary">上传
                  <i class="el-icon-upload el-icon--right"></i>
                </el-button>
              </el-upload>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="版权信息">
          <el-input v-model="form.copyright" maxlength="500" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入版权信息"></el-input>
        </el-form-item>
        <!-- <el-form-item label="自定义代码">
          <el-input v-model="form.code" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入自定义代码"></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="submit()">确定</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getWebSite, updateWebSite } from "@/api/settings"
export default {
  name: "websiteInfo",
  data() {
    return {
      form: {}
    }
  },
  methods: {
    logoSuccess(response, file, fileList) {
      this.form.logoUrl = response.data.file_name
    },
    wechatSuccess(response, file, fileList) {
      this.form.wechat = response.data.file_name
    },
    uploadError() {},
    submit() {
      updateWebSite(this.form).then(data => {
        if (data.result) {
          this.$message({
            message: "设置成功！",
            type: "success"
          })
        } else {
          this.$message.error("设置失败!" + data.errMsg)
        }
      })
    }
  },
  created() {
    getWebSite().then(data => {
      this.form = data
    })
  }
}
</script>
